package com.hg.library.ui.imageview;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.hg.highglass_library.R;

/**
 * Created by ASUS-PC on 2016/7/4.
 */
public class BatteryWhite extends ImageView implements BatteryView{

    private int percent;//55~0

    private int color;

    private Paint paint = new Paint();

    public BatteryWhite(Context context, AttributeSet attrs) {
        super(context, attrs);
        color = context.getResources().getColor(R.color.white);
        paint.setAntiAlias(true);
    }

    public void setBatteryPercent(int percent) {
        this.percent = percent;
        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) getLayoutParams();
        layoutParams.rightMargin = (int) (55-55/100f*percent);
        setLayoutParams(layoutParams);
    }

    public int getBatteryPercent(){
        return percent;
    }

    public void setColor(int color){
        this.color = color;
        paint.setColor(color);
        invalidate();
    }

    public int getColor(){
        return color;
    }

    @Override
    public void draw(Canvas canvas) {
        super.draw(canvas);
        paint.setColor(color);
        Rect rect = new Rect(3,3,55,21);
        canvas.drawRoundRect(new RectF(rect),10,10,paint);
    }
}
